package com.lagou.task16;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ExceptionCatchTest {
    public static void main(String[] args) {

        FileInputStream file = null;
        //创建一个FileInputStream类型的对象与/Users/mac/Desktop/output.json文件关联，相当于打开文件
        try {
            System.out.println("1");
            file = new FileInputStream("/Users/mac/Desktop/output1.json");
            System.out.println("2");
        } catch (FileNotFoundException e) {
            System.out.println("3");
            e.printStackTrace();
            System.out.println("4");
        }
        try {
            //相当于关闭文件
            System.out.println("5");
            file.close();
            System.out.println("6");
        } /*catch (IOException e) {
            System.out.println("7");
            e.printStackTrace();
            System.out.println("8");
        }catch (NullPointerException point){
            point.printStackTrace();
        }*/catch (Exception e){//小类型异常要放到大类型的前面，否则编译报错
            e.printStackTrace();
        }
        finally {
            System.out.println("无论发生什么我都处理");
        }
        System.out.println("结束了");

        //手动处理异常代码就会往后走，没有处理默认终止进程
    }
}
